package com.yunfeisoft.business.dao.impl;

import com.yunfeisoft.business.dao.inter.OutHospitalReceiptDao;
import com.yunfeisoft.business.model.Elder;
import com.yunfeisoft.business.model.OutHospital;
import com.yunfeisoft.business.model.OutHospitalReceipt;
import com.yunfeisoft.common.base.BaseDaoImpl;
import com.yunfeisoft.common.sql.builder.SelectBuilder;
import com.yunfeisoft.common.sql.builder.WhereBuilder;
import com.yunfeisoft.common.utils.Page;
import org.springframework.stereotype.Repository;
import org.springframework.util.ObjectUtils;

import java.util.Arrays;
import java.util.Map;

/**
 * ClassName: OutHospitalReceiptDaoImpl
 * Description: 老人出院结算单Dao实现
 * Author: Jackie liu
 * Date: 2020-06-05
 */
@Repository
public class OutHospitalReceiptDaoImpl extends BaseDaoImpl<OutHospitalReceipt, String> implements OutHospitalReceiptDao {

    @Override
    public Page<OutHospitalReceipt> queryPage(Map<String, Object> params) {
        WhereBuilder wb = new WhereBuilder();
        wb.setOrderByWithDesc("createTime");
        if (params != null) {
            initPageParam(wb, params);
            if (!ObjectUtils.isEmpty(params.get("elderName"))) {
                wb.andFullLike("e.name", params.get("elderName"));
            }
        }
        SelectBuilder builder = getSelectBuilder("r");
        builder.column("e.name as elderName")
                .rightJoin(Elder.class)
                .alias("e")
                .on("e.id = r.elderId").build();
        return queryPage(builder.getSql(), wb);
    }
}